﻿using Confluent.Kafka;
using Elasticsearch.Net;
using Md.Demo.Entity.MongoModels;
using Nest;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Md.Demo.Tools
{
    public interface IElasticSearchServer
    {
        /// <summary>
        /// Linq查询的官方Client
        /// </summary>
        IElasticClient ElasticLinqClient { get; set; }
        /// <summary>
        ///是否存在索引
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        Task<bool> IndexExistsAsync(string index = "id");

        /// <summary>
        ///新增数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="entity"></param>
        /// <param name="index"></param>
        Task CreateAsync<T>(T entity, string index = "id") where T : EsBase;

        /// <summary>
        ///批量新增
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="entity"></param>
        /// <param name="index"></param>
        Task InsertRangeAsync<T>(IEnumerable<T> entity, string index = "id") where T : EsBase;

        /// <summary>
        /// 根据索引删除数据
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        Task RemoveIndex(string index = "id");
        /// <summary>
        /// 根据索引删除数据 ID
        /// </summary>
        /// <param name="Id">实体ID</param>
        /// <param name="index"></param>
        /// <returns></returns>
        Task DeleteAsync<T>(string Id, string index = "id") where T : EsBase;
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="Id"></param>
        /// <param name="index"></param>
        /// <returns></returns>
        Task UpdateAsync<T>(T entity, string index = "id") where T : EsBase;
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <param name="index"></param>
        /// <returns></returns>

        Task<Tuple<int, IList<T>>> QueryAsync<T>(int page, int limit, string index = "id") where T : EsBase;
    }

}